"""
@author: wtf
@file: decorators.py
@time: 2024/5/12 20:31
@desc: 
"""
# 装饰器
from functools import wraps
from flask import g, redirect, url_for

def login_required(func):
    # 保存原来函数的逻辑
    @wraps(func)
    def inner(*args, **kwargs):
        if g.get("user"):
            return func(*args, **kwargs)
        else:
            return redirect(url_for("auth.user_login"))
    return inner